using System.Collections.Generic;
using NFreeMarker.Template;
using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessMethodCall
    {
        [TestFixture]
        public class When_processing_a_method_call_expression : TemplateTestsBase
        {
            [Test]
            public void Assure_the_return_value_of_the_method_is_passed_to_the_template()
            {
                SetTemplateContent("${indexOf('orld', message)}");
                AddTemplateVariable("indexOf", new IndexOfMethod());
                AddTemplateVariable("message", "Hello world");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("7"));
            }
        }
    }

    internal class IndexOfMethod : ITemplateMethodModel
    {
        public object Exec(IList<string> arguments)
        {
            if (arguments.Count != 2)
            {
                throw new TemplateModelException("Wrong number of arguments");
            }
            return new SimpleNumber(arguments[1].IndexOf(arguments[0]));
        }
    }
}
// ReSharper enable InconsistentNaming
